﻿// ===============================================================================
//  Copyright © ymind.net. All rights reserved .
//  官方网站：http://ymind.net/
//  版权所有：彦铭工作室 老陈出品
// ===============================================================================

using System;
using System.Collections;
using System.Collections.Generic;
using Lcsoft.RssEngine.Collections;
using Lcsoft.RssEngine.Shared;

namespace Lcsoft.RssEngine
{
	/// <summary>Base class for all RSS modules</summary>
	[Serializable]
	public abstract class RssModule
	{
		private readonly ArrayList _alBindTo = new ArrayList();
		private string _sNamespacePrefix = String.Empty;
		private Uri _uriNamespaceURL = RssDefault.UriValue;

		/// <summary>
		/// 
		/// </summary>
		protected RssModule()
		{
			this.ChannelExtensions = new RssModuleItemCollection();
			this.ItemExtensions = new List<RssModuleItemCollection>();
		}

		/// <summary>Collection of RSSModuleItem that are to be placed in the channel</summary>
		internal RssModuleItemCollection ChannelExtensions { get; set; }

		/// <summary>Collection of RSSModuleItemCollection that are to be placed in the channel item</summary>
		internal List<RssModuleItemCollection> ItemExtensions { get; set; }

		/// <summary>Prefix for the given module namespace</summary>
		public string NamespacePrefix
		{
			get { return this._sNamespacePrefix; }
			set { this._sNamespacePrefix = RssDefault.Check(value); }
		}

		/// <summary>URL for the given module namespace</summary>
		public Uri NamespaceURL
		{
			get { return this._uriNamespaceURL; }
			set { this._uriNamespaceURL = RssDefault.Check(value); }
		}

		/// <summary>Bind a particular channel to this module</summary>
		/// <param name="channelHashCode">Hash code of the channel</param>
		public void BindTo(int channelHashCode) { this._alBindTo.Add(channelHashCode); }

		/// <summary>Check if a particular channel is bound to this module</summary>
		/// <param name="channelHashCode">Hash code of the channel</param>
		/// <returns>true if this channel is bound to this module, otherwise false</returns>
		public bool IsBoundTo(int channelHashCode) { return (this._alBindTo.BinarySearch(0, this._alBindTo.Count, channelHashCode, null) >= 0); }
	}
}
